/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

****/
package org.activequant.core.domainmodel.account;

import static org.activequant.util.tools.IdentityUtils.equalsTo;
import static org.activequant.util.tools.IdentityUtils.safeCompare;
import static org.activequant.util.tools.IdentityUtils.safeHashCode;

import java.io.Serializable;

import org.activequant.core.types.TimeStamp;

/**
 * This is an entry for the balance class.  <br/>
 * Holds the following associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>stamp(TimeStamp)</li>
 * <li>value(double)</li>
 * </ul>
 * <br>
 * <b>History:</b><br>
 *  - [03.05.2007] Created (Ulrich Staudinger)<br>
 *  - [14.07.2007] Added persistence (Erik Nijkamp)<br>
 *  - [29.09.2007] Removed annotations (Erik Nijkamp)<br>
 *  - [02.11.2007] Added NOT_SET (Erik Nijkamp)<br>
 *  
 *  @author Ulrich Staudinger
 */
public class BalanceEntry implements Comparable<BalanceEntry>, Serializable {
	
	private static final long serialVersionUID = 7865569027729367490L;
	/**
	 * public static final double NOT_SET = -1;
	 */
	public static final double NOT_SET = -1;
	/**
	 * private Long id;
	 */
	private Long id;
    /**
     * private TimeStamp stamp; 
     */
	private TimeStamp stamp; 
	/**
	 * private double value = NOT_SET;
	 */
    private double value = NOT_SET;
    /**
     * an empty BalanceEntry constructor
     */
    public BalanceEntry() {
    }
    /**
     * constructs a BalanceEntry using the given value(double) and date(TimeStamp) to set its associated value(double) and stamp(TimeStamp)
     * @param value
     * @param date
     */
	public BalanceEntry(double value, TimeStamp date) {
	    this.value = value; 
		this.stamp = date; 
	}
	/**
	 * returns the associated id(Long)
	 * @return
	 */
	public Long getId() {
		return id;
	}
	/**
	 * sets the associated id(Long) with the given id(Long)
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * returns whether the associated id(Long) is not <code>null</code>
	 * @return
	 */
	public boolean hasId() {
		return id != null;
	}
	/**
	 * returns the associated stamp(TimeStamp)
	 * @return
	 */
	public TimeStamp getTimeStamp() {
		return stamp;
	}
	/**
	 * sets the associated stamp(TimeStamp) with the given date(TimeStamp)
	 * @param date
	 */
	public void setTimeStamp(TimeStamp date) {
		this.stamp = date;
	}	
    /**
     * returns a String in the form: "Balance Entry : ${stamp.getDate} : ${value}"
     */
    public String toString() {
        return "Balance Entry : " + stamp.getDate() + " : " + value;
    }
    /**
     * returns the associated value(double)
     * @return
     */
    public double getValue() {
        return value; 
    }
    /**
     * sets the associated value(double) with the given value(double)
     * @param value
     */
	public void setValue(double value) {
		this.value = value;
	}
	
	public int hashCode() {
		return safeHashCode(stamp);
	}
	
	public boolean equals(Object o) {
		return equalsTo(this, o);
	}
	
	public int compareTo(BalanceEntry other) {
		return safeCompare(stamp, other.stamp);
	}
}
